<?php
namespace app\common\auth;
use app\common\service\UserRole as UserRoleService;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/17
 * Time: 16:52
 */
class Auth{

    /**
     * @param $mark  权限标志
     * @param $user 用户
     * @return bool
     */
    public function checkAuth($mark,$user){

        $roleId = isset($user['role_id'])?$user['role_id']:0;

        //超级管理员 什么都可以访问
        if($roleId == '-1'){
            return true;
        }

        $userRoleService = new UserRoleService;
        $permission = $userRoleService -> getPermissionByRole($roleId);
        if(!$permission) $permission = [];

        //要设置白名单 给游客用
        $whiteList = config('whiteList');

        //检查mark在不在这个数组中
        if(in_array($mark,$permission)){
            return true;
        }elseif(in_array($mark,$whiteList)){
            return true;
        }
        return false;
    }





}